package com.sps.business.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.sps.business.domain.CcOrderInfoExcel;
import com.sps.business.domain.WebTest;
import com.sps.common.annotation.Anonymous;
import com.sps.common.annotation.RepeatSubmit;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.sps.common.annotation.Log;
import com.sps.common.core.controller.BaseController;
import com.sps.common.core.domain.AjaxResult;
import com.sps.common.enums.BusinessType;
import com.sps.business.domain.CcOrderInfo;
import com.sps.business.service.ICcOrderInfoService;
import com.sps.common.utils.poi.ExcelUtil;
import com.sps.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 订单信息Controller
 * 
 * @author ruoyi
 * @date 2024-12-11
 */
@RestController
@RequestMapping("/business/ccorderinfo")
public class CcOrderInfoController extends BaseController
{
    @Autowired
    private ICcOrderInfoService ccOrderInfoService;

    /**
     * 查询订单信息列表
     */
    @PreAuthorize("@ss.hasPermi('business:ccorderinfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(CcOrderInfo ccOrderInfo)
    {
        startPage();
        List<CcOrderInfo> list = ccOrderInfoService.selectCcOrderInfoList(ccOrderInfo);
        return getDataTable(list);
    }


    /**
     * 查询订单信息列表(根据订单分组)
     */
    @GetMapping("/listGroup")
    public TableDataInfo listGroup(CcOrderInfo ccOrderInfo)
    {
        startPage();
        List<CcOrderInfo> list = ccOrderInfoService.selectCcOrderInfoListGroup(ccOrderInfo);
        return getDataTable(list);
    }

    /**
     * 查询订单信息列表(根据订单分组)
     */
    @GetMapping("/listGroupFj")
    public TableDataInfo listGroupFj(CcOrderInfo ccOrderInfo)
    {
        startPage();
        List<CcOrderInfo> list = ccOrderInfoService.selectCcOrderInfoListGroupFj(ccOrderInfo);
        return getDataTable(list);
    }


    /**
     * 导出订单信息列表
     */
    @PreAuthorize("@ss.hasPermi('business:ccorderinfo:export')")
    @Log(title = "订单信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CcOrderInfo ccOrderInfo)
    {
        List<CcOrderInfo> list = ccOrderInfoService.selectCcOrderInfoList(ccOrderInfo);
        ExcelUtil<CcOrderInfo> util = new ExcelUtil<CcOrderInfo>(CcOrderInfo.class);
        util.exportExcel(response, list, "订单信息数据");
    }

    /**
     * 获取订单信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:ccorderinfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(ccOrderInfoService.selectCcOrderInfoById(id));
    }

    /**
     * 新增订单信息
     */
    @PreAuthorize("@ss.hasPermi('business:ccorderinfo:add')")
    @Log(title = "订单信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CcOrderInfo ccOrderInfo)
    {
        return toAjax(ccOrderInfoService.insertCcOrderInfo(ccOrderInfo));
    }

    /**
     * 修改订单信息
     */
    @PreAuthorize("@ss.hasPermi('business:ccorderinfo:edit')")
    @Log(title = "订单信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CcOrderInfo ccOrderInfo)
    {
        return toAjax(ccOrderInfoService.updateCcOrderInfo(ccOrderInfo));
    }

    @Log(title = "回传接口", businessType = BusinessType.UPDATE)
    @Anonymous
    @PostMapping("/api/passback")
    public AjaxResult passback(@RequestBody WebTest webTest)
    {
        return toAjax( ccOrderInfoService.passback(webTest));
    }


    /**
     * 删除订单信息
     */
    @PreAuthorize("@ss.hasPermi('business:ccorderinfo:remove')")
    @Log(title = "订单信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ccOrderInfoService.deleteCcOrderInfoByIds(ids));
    }


    @Log(title = "根据订单号删除", businessType = BusinessType.DELETE)
    @DeleteMapping("/deleteByOrderCode/{orderCode}")
    public AjaxResult deleteByOrderCode(@PathVariable String orderCode)
    {
        return toAjax(ccOrderInfoService.deleteCcOrderInfoByOrderCode(orderCode));
    }

    /**
     * 订单导入模板
     */
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtil<CcOrderInfoExcel> util = new ExcelUtil<CcOrderInfoExcel>(CcOrderInfoExcel.class);
        util.importTemplateExcel(response, "订单数据");
    }


    @Log(title = "导入订单", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, String pcDate) throws Exception
    {
        ExcelUtil<CcOrderInfoExcel> util = new ExcelUtil<CcOrderInfoExcel>(CcOrderInfoExcel.class);
        List<CcOrderInfoExcel> orderList = util.importExcel(file.getInputStream());
        String operName = getUsername();
        String message = ccOrderInfoService.importOrder(orderList, pcDate, operName);
        return success(message);
    }


    /**
     * 下发分拣任务
     */
    @Log(title = "下发分拣任务", businessType = BusinessType.UPDATE)
    @RepeatSubmit(interval = 3000, message = "请求过于频繁")
    @DeleteMapping("/fjrwCcorderinfo/{orderCode}")
    public AjaxResult fjrwCcorderinfo(@PathVariable String orderCode)
    {
        return toAjax(ccOrderInfoService.fjrwCcOrderInfoByorderCode(orderCode));
    }


    /**
     * 更新分拣单打印状态
     */
    @Log(title = "更新打印状态", businessType = BusinessType.UPDATE)
    @RepeatSubmit(interval = 1000, message = "请求过于频繁")
    @PutMapping("/editOrderDyStatus")
    public AjaxResult editOrderDyStatus(@RequestBody CcOrderInfo ccOrderInfo)
    {
        return toAjax(ccOrderInfoService.editOrderDyStatus(ccOrderInfo));
    }

    /*
     * 手机端扫码亮灯接口()
     */
    @Log(title = "移动端分拣亮灯", businessType = BusinessType.UPDATE)
    @RepeatSubmit(interval = 3000, message = "请求过于频繁")
    @DeleteMapping("/removeLd/{res1}")
    public AjaxResult removeLd(@PathVariable String res1) throws Exception {
        return toAjax(ccOrderInfoService.removeLd(res1));
    }





}
